﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TheSimGer
{
    /// <summary>
    /// 学习类型
    /// </summary>
    public enum LearnAttribute 
    { 
        NengLi,
        YuLe,
        BuffAdd, //添加Buff
    }

    public static class EunmHelper 
    { 
        public static LearnAttribute GetRandom()
        {
            Random ran = new Random(Guid.NewGuid().GetHashCode());
            int c = Enum.GetNames(typeof(LearnAttribute)).Length;
            var aa = Enum.GetName(typeof(LearnAttribute), ran.Next(c));
            Enum.TryParse(aa, out LearnAttribute RR);
            return RR;
        }

        public static string GetNameFrmEnum(LearnAttribute LA) 
        {
            if (LA == LearnAttribute.BuffAdd)
            {
                return "BUFF";
            }
            else if (LA == LearnAttribute.NengLi) 
            {
                return "能力";
            }
            else if (LA == LearnAttribute.YuLe)
            {
                return "娱乐";
            }

            return "未知";
        }
    }

    /// <summary>
    /// 玩家学习结果
    /// </summary>
    public class LearnResult
    {
        public LearnAttribute TriggerLearnType = LearnAttribute.NengLi;
        public int TriggerValue = 0;
        public TheBuff TriggerBuff = null;
        public string Comment = "";
    }

    public class LearnResultManager 
    {
        /// <summary>
        /// 随机分配学习结果
        /// </summary>
        public static (List<LearnResult>,string) GetRandomLearnResult() 
        {
            var RR = new List<LearnResult>();
            var RandomCount = TheRandom.Range(1, 3);
            var RStr = "";
            for (int loopa = 0; loopa < RandomCount; loopa++)
            {
                var RType = EunmHelper.GetRandom();
                if (RType == LearnAttribute.NengLi || RType == LearnAttribute.YuLe)
                {
                    var RandomInterger = TheRandom.Range(5, 20);
                    RStr += $"{ EunmHelper.GetNameFrmEnum(RType) }+{RandomInterger} ";
                    RR.Add(new LearnResult { Comment = RStr, TriggerLearnType = RType, TriggerValue = RandomInterger });
                }
                else if (RType == LearnAttribute.BuffAdd) 
                {
                    var RandomBuff = BuffHelper.GenRandom(new List<Action>());
                    RStr += $"{ EunmHelper.GetNameFrmEnum(RType) }+{RandomBuff.Name} ";
                    RR.Add(new LearnResult { Comment = RStr, TriggerLearnType = RType, TriggerBuff = RandomBuff, });
                }
            }

            return (RR, RStr);
        }
    }
}
